<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%
	String path = request.getContextPath();
	String theme="ui-pepper-grinder";	
	%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/static/<%=theme%>/easyui.css">
<script type="text/javascript"
	src="<%=path%>/static/jquery.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/static/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/static/easyui-lang-zh_CN.js"></script>

</head>
<body>
<#if showStyle=="TREE"||showStyle=="TREE_TABLE">
	<div class="easyui-panel" style="padding: 5px">
		<ul class="easyui-tree" id="${name?uncap_first}_tt" style="height: 400px;"
			data-options="url:'<%=path%>/${name?uncap_first}/children',method:'get',
			animate:true,lines:true,loadFilter:${name?uncap_first}_myLoadFilter,
			onContextMenu: function(e,node){
					e.preventDefault();
					$(this).tree('select',node.target);
					$('#${name?uncap_first}_mm').menu('show',{
						left: e.pageX,
						top: e.pageY
					});
				}"></ul>
	</div>
	  <!-- menu -->
	 <div  id="${name?uncap_first}_mm" class="easyui-menu" style="width:120px;">
		 <div  onclick="${name?uncap_first}_add();" data-options="iconCls:'icon-add'">添加</div> 
		 <div  onclick="${name?uncap_first}_del();" data-options="iconCls:'icon-remove'">删除</div> 
		 <div  onclick="${name?uncap_first}_edit();" data-options="iconCls:'icon-edit'">修改</div>
		 <div  onclick="${name?uncap_first}_detail();" data-options="iconCls:'icon-ok'">详情</div>
		 <div  onclick="${name?uncap_first}_refresh();" data-options="iconCls:'icon-reload'">刷新</div>
		 <div  onclick="${name?uncap_first}_expandAll();" data-options="iconCls:'icon-reload'">展开</div>
	</div>
</#if>
<#if showStyle=="TABLE">
<!-- table -->
	<table id="${name?uncap_first}_dg" data-options="rownumbers:true,toolbar:'#${name?uncap_first}_tb',footer:'#${name?uncap_first}_ft'"></table>
	<!-- search area -->
	<div id="${name?uncap_first}_tb" style="padding: 2px 5px; text-align: right;width: 100%;">
 		 <div style="width: 80%;float:left; text-align: left;">
 		 	<#list list?sort_by("list_query") as col> 
 		 		 <#if col.list_query=="Y">
 		 		 	<#if col.data_type=="date"||col.data_type=="datetime">
 		 		 	 ${col.column_comment}:<input class="easyui-${col.is_nullable}" id="${name?uncap_first}_q_${col.column_alias}_from" name="${col.column_alias}_from" style="width: 110px">
 		 		 	 至  
 		 		 	  ${col.column_comment}:<input class="easyui-${col.is_nullable}" id="${name?uncap_first}_q_${col.column_alias}_to" name="${col.column_alias}_to" style="width: 110px">  
 		 		    <#else> 						 
					   ${col.column_comment}: <input class="easyui-${col.is_nullable}" <#if col.is_nullable=="combobox"> data-options="valueField:'dictvalue',textField:'dictname',url:'<%=path %>/dict/all?dicttype=STATUS&dictstatus=E'" </#if> id="${name?uncap_first}_q_${col.column_alias}" name="${col.column_alias}" style="width: 110px"> 					  
 		 			</#if>
 		 		 </#if>
 		 	</#list> 			  		 
 		</div>
 		<div style=" text-align: center;">
	 			<span onclick="${name?uncap_first}_search();" class="easyui-linkbutton" >查询</span>
				<span onclick="${name?uncap_first}_reset();" class="easyui-linkbutton" >清空</span> 
		</div> 
 	</div>
	<!-- buttons -->
	<div id="${name?uncap_first}-ft" style="padding: 2px 5px; text-align: right;">
		<span onclick="${name?uncap_first}_detail();" class="easyui-linkbutton">详情</span> 
		<span onclick="${name?uncap_first}_add();" class="easyui-linkbutton">新增</span> 
		<span onclick="${name?uncap_first}_edit();" class="easyui-linkbutton">修改</span>
	    <span onclick="${name?uncap_first}_del();" class="easyui-linkbutton">删除</span>
	</div>	
</#if>
	<!-- detail -->
	<div id="${name?uncap_first}_detail-win" class="easyui-window" style="padding: 5px"
		data-options="title:'详情',width:400,modal:true,closed:true,collapsible:false,minimizable:false,iconCls:'icon-help'">
		<div class="easyui-panel" style="width: 100%; text-align: center;adding: 5px"> 				 
			<#list list as col>
			 <div style="width: 250px; text-align: left; padding: 10px 5px 5px 20px;">
				 ${col.column_comment!"${col.column_name}"}: <span id="${name?uncap_first}_d_${col.column_alias}"></span>			 
				</div>
			</#list> 
		</div>
	</div>
	
	<!-- add   -->
	<div id="${name?uncap_first}_a-win" class="easyui-window" style="padding: 5px"
		data-options="title:'新增',modal:true,closed:true,collapsible:false,minimizable:false,iconCls:'icon-save'">
		<div class="easyui-panel" style="width: 600px;">
			<form id="${name?uncap_first}_a-ff" class="easyui-form" method="post"
				data-options="novalidate:false">
				<div style="width: 100%; padding-top: 10px;">
					<div style="width: 100%; float: left;">
					 <#list list?sort_by("new_show") as col>
						<#if col.new_show=="Y">
						<div style="width: 48%; float: left;padding-left: 2%;">
						   ${col.column_comment}:<input class="easyui-${col.is_nullable}" data-options="required:true<#if col.is_nullable=="combobox"> ,valueField:'dictvalue',textField:'dictname',url:'<%=path %>/dict/all?dicttype=STATUS&dictstatus=E'</#if>" id="${name?uncap_first}_a-${col.column_alias}"  name="${col.column_alias}" style="width: 110px"> 
						</div>					 
						</#if>
					 </#list> 
					</div>
					<div style="width: 100%; text-align: center; ">
						    <span onclick="${name?uncap_first}_save();" class="easyui-linkbutton">保存</span>
						    <span onclick="${name?uncap_first}_clear_closeWin($('#${name?uncap_first}_a-ff'),$('#${name?uncap_first}_a-win'));" class="easyui-linkbutton">取消</span>
					</div>
				</div>
			</form>
		</div>
	</div>
	<!-- modify   -->
	<div id="${name?uncap_first}_e-win" class="easyui-window" style="padding: 5px"
		data-options="title:'修改',modal:true,closed:true,collapsible:false,minimizable:false,iconCls:'icon-save'">
		<div class="easyui-panel" style="width: 600px;">
			<form id="${name?uncap_first}_e-ff" class="easyui-form" method="post"
				data-options="novalidate:false">
				<div style="width: 100%; padding-top: 10px;">
					<div style="width: 100%; float: left;">
					 <#list list?sort_by("update_show") as col>
					 <#if col.update_show=="N">
					 	<input type="hidden" id="${name?uncap_first}_e-${col.column_alias}" name="${col.column_alias}" >
					 <#else>					
						<div style="width: 48%; float: left;padding-left: 2%;">
						  ${col.column_comment}:<input class="easyui-${col.is_nullable}" data-options="required:true<#if col.is_nullable=="combobox"> ,valueField:'dictvalue',textField:'dictname',url:'<%=path %>/dict/all?dicttype=STATUS&dictstatus=E'</#if>" id="${name?uncap_first}_e-${col.column_alias}"  name="${col.column_alias}" style="width: 110px">			 		 								 
						</div>						 
					 </#if>
					</#list> 
					</div>
					<div style="width: 100%; text-align: center; ">
						<span onclick="${name?uncap_first}_update();" class="easyui-linkbutton">保存</span>  
						<span onclick="${name?uncap_first}_clear_closeWin($('#${name?uncap_first}_e-ff'),$('#${name?uncap_first}_e-win'));" class="easyui-linkbutton">取消</span>
					</div>
				</div>

			</form>
		</div>
	</div>
 <!-- function -->
 <script type="text/javascript">
 var ctx='<%=request.getContextPath()%>';
 <#if showStyle=="TREE"||showStyle=="TREE_TABLE">	
	function ${name?uncap_first}_myLoadFilter(data, parent){
		return data;
	}
	function ${name?uncap_first}_refresh() {
		$('#${name?uncap_first}_tt').tree('reload');
	}
	$("#${name?uncap_first}_tt").tree({'onClick':function(node){
		$("#${name?uncap_first}_tt").tree('expand',node.target);
	}});
	function ${name?uncap_first}_expandAll(){
		$('#${name?uncap_first}_tt').tree('expandAll');
	}
 </#if>
 <#if showStyle=="TABLE">
 //init table
	$("#${name?uncap_first}_dg").datagrid({
		url : ctx + '/${name?uncap_first}/list',
		width : 'auto',
		pageSize : 20,
		pageList : [ 20, 30, 40 ],
		nowrap : true,
		striped : true,
		fitColumns : true,
		pagination : true,
		remoteSort : false,
		title : '列表页面',
		loadMsg : '加载中...',
		columns : [ [			
	<#list list?sort_by("list_show") as col>
	<#if col.column_key=="PRI"&& col.list_show=="N">
		{
			field : '${pkCol.column_alias}',
			checkbox : true
		 } ,
	</#if>
	 <#if col.list_show=="Y">
		<#if col_has_next >
				 <#if col.data_type=="PRI">	
				{
					field : '${col.column_alias}',
					checkbox : true
				 } ,				 
				<#else>
				 {
					field : '${col.column_alias}',
					title : '${col.column_comment}',
					width : '180',
					align : 'center'
				 } ,
				</#if>
		<#else>
		 	 <#if col.data_type=="PRI">	
				{
					field : '${col.column_alias}',
					checkbox : true
				 } ,			 
			<#else>
				  {
					field : '${col.column_alias}',
					title : '${col.column_comment}',
					width : '180',
					align : 'center'
				 } 
			 </#if>					 
	    </#if>
	 </#if>
	</#list>] ]}); 
 // search 
	function ${name?uncap_first}_search() {
	$("#${name?uncap_first}_dg").datagrid('load', {
	<#list list?sort_by("list_query") as col>
	 <#if col.list_query=="Y">
	 <#if col_has_next >
 	 	<#if col.data_type=="date"||col.data_type=="datetime">
 		 	  ${col.column_alias}_from : $("#${name?uncap_first}_q_${col.column_alias}_from").${col.is_nullable}('getValue') ,
 		  	  ${col.column_alias}_to  :$("#${name?uncap_first}_q_${col.column_alias}_to").${col.is_nullable}('getValue'), 			 
 		<#else> 				 
 			   ${col.column_alias} :$("#${name?uncap_first}_q_${col.column_alias}").${col.is_nullable}('getValue'), 			 	
 		</#if>
	<#else>
		<#if col.data_type=="date"||col.data_type=="datetime">
 		 	  ${col.column_alias}_from : $("#${name?uncap_first}_q_${col.column_alias}_from").${col.is_nullable}('getValue') ,
 		  	  ${col.column_alias}_to  :$("#${name?uncap_first}_q_${col.column_alias}_to").${col.is_nullable}('getValue') 			 
 		<#else> 				 
 			   ${col.column_alias} :$("#${name?uncap_first}_q_${col.column_alias}").${col.is_nullable}('getValue')			 	
 		</#if>		
 	</#if>	 
   </#if>	
</#list> });
		}
 // reset search area	
	function ${name?uncap_first}_reset() {
 <#list list as col>	 
 	 <#if col.list_query=="Y">
	 	<#if col.data_type=="date"||col.data_type=="datetime">
	 	  $("#${name?uncap_first}_q_${col.column_alias}_from").${col.is_nullable}('setValue','') ;
	  	  $("#${name?uncap_first}_q_${col.column_alias}_to").${col.is_nullable}('setValue','') ;		 
		<#else>		 
		  $("#${name?uncap_first}_q_${col.column_alias}").${col.is_nullable}('setValue','') ;		
		</#if>
	 </#if> 	 
	</#list>
	} 
 </#if>
 // clear form & close win 
 
	function ${name?uncap_first}_clear_closeWin(f_target,w_target){
		if(f_target){
			f_target.form('clear');
		}
		if(w_target){
			w_target.window('close');	
		}
	}
  //show add 
	function ${name?uncap_first}_add(){
	<#if showStyle=="TREE"||showStyle=="TREE_TABLE">
		var node = $('#${name?uncap_first}_tt').tree('getSelected');
		if(node){
			$("#${name?uncap_first}_a-win").window('open');
		}else{
			$.messager.alert('', '请先选择节点!', 'warning');
		}
	<#else>
		$("#${name?uncap_first}_a-win").window('open');
	</#if>
	}
    //show edit 
	function  ${name?uncap_first}_edit(){
	<#if showStyle=="TREE"||showStyle=="TREE_TABLE">
		var node = $('#${name?uncap_first}_tt').tree('getSelected');
		if(node){
			$("#${name?uncap_first}_e-ff").form('load',ctx+'/${name?lower_case}/detail?${pkCol.column_alias}='+node.${pkCol.column_alias});			 
		}else{
			$.messager.alert('', '请先选择节点!', 'warning');
		}
	<#else>
		var node = $("#${name?uncap_first}_dg").datagrid("getSelections");
		if(node.length != 1 ){
			$.messager.alert('', '只能修改一条记录!', 'warning');
			return;
		}else{
			$("#${name?uncap_first}_e-ff").form('load', ctx + '/${name?lower_case}/detail?${pkCol.column_alias}=' + node[0].${pkCol.column_alias});			
		}		
	</#if>
		$("#${name?uncap_first}_e-win").window('open');	
	}
	//save  
	function ${name?uncap_first}_save() {
		if ($("#${name?uncap_first}_a-ff").form('validate')) {			 
				$("#${name?uncap_first}_a-ff").form('submit', {
					url : ctx + '/${name?uncap_first}/save',
					success : function(data) {
						var data = eval('(' + data + ')');
						if(data.success){
						$.messager.show({
							msg : data.msg,
							timeout:2000,
							showType : 'show'
						});
						${name?uncap_first}_clear_closeWin($("#${name?uncap_first}_a-ff"),$("#${name?uncap_first}_a-win"));
					<#if showStyle=="TREE"||showStyle=="TREE_TABLE">
						$('#${name?uncap_first}_tt').tree('reload');						 
					<#else>
						${name?uncap_first}_search();
					</#if>}else{
						$.messager.alert('错误信息',data.msg,'error');		
						}
					
					}
				});		 
		}
	}
	// updaate 
	function ${name?uncap_first}_update(){
		if ($("#${name?uncap_first}_e-ff").form('validate')) {
			$("#${name?uncap_first}_e-ff").form('submit', {
						url : ctx + '/${name?uncap_first}/update',
						success : function(data) {
							var data = eval('(' + data + ')');
							if(data.success){
							$.messager.show({msg : data.msg,timeout:2000,showType : 'show'});
							${name?uncap_first}_clear_closeWin($("#${name?uncap_first}_e-ff"),$("#${name?uncap_first}_e-win"));
						<#if showStyle=="TREE"||showStyle=="TREE_TABLE">
							$('#${name?uncap_first}_tt').tree('reload');
						<#else>
							${name?uncap_first}_search();
						</#if>}else{
							$.messager.alert('错误信息',data.msg,'error');		
						 }
						
						}
					});
		 }
	}	
 //detail 
	function ${name?uncap_first}_detail(){
	<#if showStyle=="TREE"||showStyle="TREE_TABLE">
		var node = $('#${name?uncap_first}_tt').tree('getSelected');
		if(!node){
			$.messager.alert('', '请先选择节点!', 'warning');
			return;
		}
		var pk = node.${pkCol.column_alias};
	<#else>
		var node = $("#${name?uncap_first}_dg").datagrid("getSelections");
		if (node.length != 1) {
			$.messager.alert('', '只能查看一条记录!', 'warning');
			return;
		}
		var pk = node[0].${pkCol.column_alias};
	</#if>			
		$.post(ctx+'/${name?uncap_first}/detail',{'${pkCol.column_alias}':pk},function(data){
			if(data){
				<#list list as col> 
				  $("#${name?uncap_first}_d_${col.column_alias}").html(data.${col.column_alias});
				</#list>					 
				$("#${name?uncap_first}_detail-win").window('open');
			}
		},'json');		
	}
 //delete 
	function ${name?uncap_first}_del() {			 
 <#if showStyle=="TABLE">
	   var node = $("#${name?uncap_first}_dg").datagrid("getSelections");
	   if (node.length > 0) {
		$.messager.confirm('', '确定要删除吗?', function(r) {
			if (r) {
				var ids = new Array();
				for (var i = 0; i < node.length; i++) {
					ids.push(node[i].${pkCol.column_alias});
				}
				$.post(ctx + '/${name?uncap_first}/del', {'pk' : ids}, 
					function(data) {
						if (data.success) {
							$.messager.show({msg : data.msg,showType : 'show'});
							${name?uncap_first}_search();
						} else {
							$.messager.alert('', data.msg, 'error');
						}
					}, 'json');
			}
		});
	} else {
		$.messager.alert('', '请选择记录!', 'warning');
	}
<#else>
	  var node = $('#${name?uncap_first}_tt').tree('getSelected');
	  if(node&&node.pid==0){
			$.messager.alert('警告','根节点不能删除！','warning');			 
			return false;
	  }
	if (node.children&&node.children.length>0) {
		$.messager.show({msg : '非叶子节点，不能删除！',showType : 'show'});
		return false;
	}
	if (node) {
		$.messager.confirm('', '确定要删除本节点吗?', function(r) {
			if (r) {
			 var ids = new Array(); 
			 ids.push(node.${pkCol.column_alias});					 
			 $.post(ctx + '/${name?uncap_first}/del', {'pk' : ids},
					function(data) {
						if (data.success) {
							$.messager.show({msg : data.msg,showType : 'show'});
							$('#${name?uncap_first}_tt').tree('remove', node.target);
						} else {
							$.messager.alert('', data.msg, 'error');
						}
					}, 'json');
			}
		});
	} else {
		$.messager.alert('', '请先选择节点!', 'warning');
	}  
 </#if>
	} 
</script>
</body>
</html>